package tests;

import common.Utils;
import org.openqa.selenium.By;

public class LoginPage extends Utils {

    public static String url = "http://127.0.0.1:58080/sign-in.html";
    public LoginPage() {
        super(url);
    }

    /*
     * 检查页面是否能正常访问
     * */
    public void loginPageRight() throws InterruptedException {
        //通过查看页面元素是否存在来检查页面加载成功与否
        //检查用户登录板块
        driver.findElement(By.cssSelector("body > div > div > div > div:nth-child(1) > div > div.card.card-md > div"));
        //检查登录按钮
        driver.findElement(By.cssSelector("#submit"));
    }

    //检查登录功能：成功登录
    public void LoginSuc() throws InterruptedException {
        driver.findElement(By.cssSelector("#username")).sendKeys("Dove");
        driver.findElement(By.cssSelector("#password")).sendKeys("123456");
        driver.findElement(By.cssSelector("#submit")).click();

        //检查登录之后是否登录成功

        //检查“搜索框“是否存在
        driver.findElement(By.cssSelector("body > div.page > header.navbar.navbar-expand-md.navbar-light.d-print-none > div > div > div.nav-item.d-none.d-md-flex.me-3 > div > form > div > input"));
        //检查“发布帖子”按钮是否存在
        driver.findElement(By.cssSelector("#bit-forum-content > div.page-header.d-print-none > div > div > div.col-auto.ms-auto.d-print-none > div > a.btn.btn-primary.d-none.d-sm-inline-block.article_post"));

//       driver.navigate().back();
    }

    //检查登录功能：异常登录，输入用户名错误
    public void LoginFail() throws InterruptedException {

        //通过 clear 保证输入框没有文本信息
//        driver.findElement(By.cssSelector("#username")).clear();
//        driver.findElement(By.cssSelector("#password")).clear();
        //或者直接点击“刷新”
        driver.navigate().refresh();

        driver.findElement(By.cssSelector("#username")).sendKeys("zhangsan");
        driver.findElement(By.cssSelector("#password")).sendKeys("123456");
        driver.findElement(By.cssSelector("#submit")).click();
        Thread.sleep(3000);
        driver.navigate().back();
        driver.quit();
    }

}
